/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package it.iubar.tkdscore;


import java.util.Hashtable;

import org.lwjgl.input.Controllers;
import org.lwjgl.input.Keyboard;


/**
 * @author Heiko Schmitt
 *
 */
public class KeyMapping
{
	public static final int BUTTON_PRESSED = (1 << 8);
	public static final int AXIS_MINUS = (1 << 8);
	public static final int AXIS_PLUS = (2 << 8);

       public static final int CONST_LEFT_TOP = 4;
       public static final int CONST_LEFT_BOTTOM = 6;

       public static final int CONST_RIGHT_TOP = 5;
       public static final int CONST_RIGHT_BOTTOM = 7;

       public static final int CONST_SHORTCUT_1 = 0;
       public static final int CONST_SHORTCUT_2 = 1;
       public static final int CONST_SHORTCUT_3 = 2;
       public static final int CONST_SHORTCUT_4 = 3;

       public static int CONFIG_LEFT_TOP = 4;
       public static int CONFIG_LEFT_BOTTOM = 6;

       public static int CONFIG_RIGHT_TOP = 5;
       public static int CONFIG_RIGHT_BOTTOM = 7;

       public static int CONFIG_SHORTCUT_1 = 0;
       public static int CONFIG_SHORTCUT_2 = 1;
       public static int CONFIG_SHORTCUT_3 = 2;
       public static int CONFIG_SHORTCUT_4 = 3;


	/**
	 * Generate eventID.<BR>
	 * keyID: Keyboard-KeyID, or ButtonID or AxisID<BR>
	 * keyState:<BR>
	 * Keyboard/Button: 0 released, 1 pressed
	 * Axis: 0 middle, 1 Plus, -1 Minus
	 * @param controllerID
	 * @return
	 */
	public int getEventID(int controllerID, int keyID, int keyState, boolean isAxis)
	{
		keyID++; //Avoid 0 keyID

		int eventID = controllerID;
		if (controllerID == 0)
		{
			//Keyboard
			eventID = eventID | (keyID << 16);
			eventID = eventID | ((keyState == 1) ? KeyMapping.BUTTON_PRESSED : 0);
		}
		else
		{
			if (isAxis)
			{
				eventID = eventID | (keyID << 24);
				eventID = eventID | (keyState < 0 ? KeyMapping.AXIS_MINUS : (keyState > 0 ? KeyMapping.AXIS_PLUS : 0));
			}
			else
			{
				eventID = eventID | (keyID << 16);
				eventID = eventID | ((keyState == 1) ? KeyMapping.BUTTON_PRESSED : 0);
			}
		}
		return eventID;
	}

    public void processEvent(int eventID) {
        TkdGlobal.print("eventID: " + eventID);
    }


}

